/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.uoc.tdp.server.impl;

import edu.uoc.tdp.common.EIssueException;
import edu.uoc.tdp.common.SubsystemConnect;
import edu.uoc.tdp.dal.*;
import edu.uoc.tdp.entity.*;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.List;

/**
 * @author tomeu
 * Per a que funcioni s'ha de fer la gestió de excepcions dins del métodes.
 */
public class SubsystemConnectImpl extends java.rmi.server.UnicastRemoteObject
        implements SubsystemConnect, Serializable {

    private ManagementDb mngDB;

    /**
     * Consutructor por defecto
     * @throws RemoteException 
     */
    public SubsystemConnectImpl() throws RemoteException, EIssueException {
        super();
    }

    public String test() throws RemoteException {
        System.out.println("test()");
        return new String("test Gestor Conexión with RMI!");
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////
    //
    //  USUARIS / Login 
    //
    ///////////////////////////////////////////////////////////////////////////////////////////////    
    /**
     * USERS - Login
     * @param email
     * @param password
     * @return User
     * @throws RemoteException
     * @throws EIssueException 
     */
    public User Login(String email, String password) throws RemoteException, EIssueException {
        try {
            ManagementUsers mngRq = new ManagementUsers();
            return mngRq.Login(email, password);
        } catch (Exception e) {
            throw new EIssueException(e.getMessage());
        }
    }

    public boolean PayBooking(int bookingId, double amount) throws RemoteException, EIssueException {
        try {
            ManagementBookings mngRq = new ManagementBookings();
            return mngRq.PayBooking(bookingId, amount);
        } catch (Exception e) {
            throw new EIssueException(e.getMessage());
        }
    }

    public boolean CancelBooking(int bookingId, String userName) throws RemoteException, EIssueException {
        try {
            ManagementBookings mngRq = new ManagementBookings();
            return mngRq.CancelBooking(bookingId, userName);
        } catch (Exception e) {
            throw new EIssueException(e.getMessage());
        }
    }



    public List<Booking> GetAllBookings(String userid, String from, String to) throws RemoteException, EIssueException {
        try {
            ManagementBookings mngRq = new ManagementBookings();
            return mngRq.GetAllBookings(userid, from, to);
        } catch (Exception e) {
            throw new EIssueException(e.getMessage());
        }
    }

    public List<Resource> GetOneBookingResources(int bookingid) throws RemoteException, EIssueException {
                try {
            ManagementBookingResources mngRq = new ManagementBookingResources();
            return mngRq.GetOneBookingResources(bookingid);
        } catch (Exception e) {
            throw new EIssueException(e.getMessage());
        }
    }

    public boolean SaveBooking(Booking booking) throws RemoteException, EIssueException {
        try {
            ManagementBookings mngRq = new ManagementBookings();
            return mngRq.SaveBooking(booking);
        } catch (Exception e) {
            throw new EIssueException(e.getMessage());
        }
    }

    public boolean SaveBookingResource(int bookingId, int resourceId) throws RemoteException, EIssueException {
        try {
            ManagementBookingResources mngRq = new ManagementBookingResources();
            return mngRq.SaveBookingResource(bookingId,resourceId);
        } catch (Exception e) {
            throw new EIssueException(e.getMessage());
        }
    }

    public List<Booking> GetAllBookings() throws RemoteException, EIssueException {
         try {
            ManagementBookings mngRq = new ManagementBookings();
            return mngRq.GetAllBookings();
        } catch (Exception e) {
            throw new EIssueException(e.getMessage());
        }
    }
    public int GetNewBookingId ()throws RemoteException, EIssueException{
        try {
            ManagementBookings mngRq = new ManagementBookings();
            return mngRq.GetNewBookingId();
        } catch (Exception e) {
            throw new EIssueException(e.getMessage());
        }
    }

    public double CalcPrice(int bookingId) throws RemoteException, EIssueException {    
        try {
            ManagementBookings mngRq = new ManagementBookings();
            return mngRq.CalcPrice(bookingId);
        } catch (Exception e) {
            throw new EIssueException(e.getMessage());
        }
    }
    
    public int GetPriceBooking(int bookingId) throws RemoteException, EIssueException {    
        try {
            ManagementBookings mngRq = new ManagementBookings();
            return mngRq.GetPriceBooking(bookingId);
        } catch (Exception e) {
            throw new EIssueException(e.getMessage());
        }
    }

 
}
